local xunji = fk.CreateSkill{
    name = "jin_heg__xunji",
}

Fk:loadTranslationTable{
    ["jin_heg__xunji"] = "勋济",
    [":jin_heg__xunji"] = "你使用【杀】可以多指定两个目标，当你以此法使用【杀】结算后，若此【杀】对所有目标均造成过伤害，则此【杀】不计入次数限制。",
    ["#jin_xunji-choose"] = "勋济：你可以为此%arg多指定两个目标",
    ["@zq__xunji-turn"] = "勋济",

    ["$jin_heg__xunji1"] = "天统之境，岂容丑虏犯边！",
    ["$jin_heg__xunji2"] = "凉州有危，臣者当济。",
}

xunji:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(xunji.name) and data.card.trueName == "slash" and
      #data:getExtraTargets() > 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 2,
      targets = data:getExtraTargets(),
      skill_name = xunji.name,
      prompt = "#jin_xunji-choose:::"..data.card:toLogString(),
      cancelable = true,
    })
    if #tos > 0 then
      room:sortByAction(tos)
      event:setCostData(self, {tos = tos})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    for _, p in ipairs(event:getCostData(self).tos) do
      data:addTarget(p)
    end
    if not data.extraUse then
      data.extra_data = data.extra_data or {}
      data.extra_data.zq__xunjim = true
    end
  end,
})

xunji:addEffect(fk.CardUseFinished, {
  can_refresh = function (self, event, target, player, data)
    return target == player and data.card.trueName == "slash" and
      data.extra_data and data.extra_data.zq__xunjim and data.damageDealt and
      table.every(data.tos, function (p)
        return data.damageDealt[p] and data.damageDealt[p] > 0
      end) and
      not data.extraUse
  end,
  on_refresh = function (self, event, target, player, data)
      player:broadcastSkillInvoke(xunji.name)
      player.room:notifySkillInvoked(player, xunji.name, "offensive")
      player:addCardUseHistory("slash", -1)
      data.extraUse = true
  end,
})

return xunji